<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>LocalStorage 示例</title>
    <style>
        body {
            display: flex;
            flex-direction: column;
            align-items: center;
            margin-top: 50px;
        }
    </style>
</head>
<body>
    <h1>LocalStorage 示例</h1>
    <input type="text" id="inputData" placeholder="输入数据" />
    <button id="saveButton">保存数据</button>
    <button id="loadButton">加载数据</button>
    <button id="deleteButton">删除数据</button>
    <p id="output"></p>

    <script>
        const inputData = document.getElementById('inputData');
        const output = document.getElementById('output');

        // 保存数据到 LocalStorage
        document.getElementById('saveButton').addEventListener('click', () => {
            const data = inputData.value;
            localStorage.setItem('myData', data); // 保存数据
            output.textContent = '数据已保存！';
            inputData.value = ''; // 清空输入框
        });

        // 从 LocalStorage 加载数据
        document.getElementById('loadButton').addEventListener('click', () => {
            const data = localStorage.getItem('myData'); // 读取数据
            output.textContent = data ? `加载的数据: ${data}` : '没有找到数据！';
        });

        // 从 LocalStorage 删除数据
        document.getElementById('deleteButton').addEventListener('click', () => {
            localStorage.removeItem('myData'); // 删除数据
            output.textContent = '数据已删除！';
        });
    </script>
</body>
</html>
